﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Control;

namespace FronteraAJAX.RegistroPrincipal
{
    public partial class Inicio : System.Web.UI.Page
    {



        #region Atributos

        IControl control;

        #endregion

        #region Propiedades

        /// <summary>
        /// Propiedad para el manejo del control
        /// </summary>
        private ControlAlumno controlAlumno
        {
            get
            {
                if (Session["ControlAlumno"] == null) return null;
                else return ((ControlAlumno)Session["ControlAlumno"]);
            }
        }
        /// <summary>
        /// Propiedad para el manejo del state
        /// </summary>
        private StateAlumno stateAlumno
        {
            get
            {
                if (Session["ControlAlumno"] == null) return null;
                else return (StateAlumno)((ControlAlumno)Session["ControlAlumno"]).State;
            }
        }
        #endregion







        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                IniciaContol();
            }
            control = (ControlAlumno)Session["ControlAlumno"];
        }
        private void IniciaContol()
        {
            ControlAlumno controInicial = new ControlAlumno();
            StateAlumno StateInicial = new StateAlumno();
            control = controInicial;
            control.State = StateInicial;
            Session["ControlAlumno"] = control;
        }
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
          controlAlumno.ObtenerUsuario(Login1.UserName,Login1.Password);
          if (stateAlumno.Usuario.Valido)
              Response.Redirect(Page.ResolveClientUrl("~/RegistroPrincipal/RegistrarClientes.aspx"));
        }

        protected void Page_PreRender()
        {
            Session["ControlAlumno"] = control;
        }
    }
}
